package com.cnhis.cloudhealth.clinical.medical.base.dao;

import com.cnhis.cloudhealth.commons.dao.BaseDao;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class MpatientInfoDao extends BaseDao {
    /**
     * @Description:(病人列表)
     * @param '[map]'
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws
     * @author chengshaowei
     * @date 2016/9/19 10:30
     */
    public Map<String, Object> findPatientList(Map map) throws Exception {
        List list = this.queryForList("MpatientInfo.findPatientList", map);
        Map<String, Object> rmap = new HashMap<String, Object>();
        rmap.put("list", list);
        return rmap;
    }

    /**
     * @Description:(病人详细信息门诊)
     * @param '[map]'
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws
     * @author chengshaowei
     * @date 2016/9/19 10:33
     */
    public Map<String, Object> findPatientInfo(Map map) throws Exception {
        return (Map<String, Object>) this.queryToObject("MpatientInfo.findPatientInfo", map);
    }
    /**
     * @Description:(病人详细信息住院)
     * @param '[map]'
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws
     * @author chengshaowei
     * @date 2016/9/19 10:33
     */
    public Map<String, Object> findHosPatientInfo(Map map) throws Exception {
        return (Map<String, Object>) this.queryToObject("MpatientInfo.findHosPatientInfo", map);
    }
    /**
     * @Description:(病人医嘱内容 門診)
     * @param '[map]'
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws
     * @author chengshaowei
     * @date 2016/9/19 10:33
     */
    public Map<String, Object> findOutAdvice(Map map) throws Exception {
        List list = this.queryForList("MpatientInfo.findOutAdvice", map);
        Map<String, Object> rmap = new HashMap<String, Object>();
        rmap.put("list", list);
        return rmap;
    }

    /**
     * @Description:(病人医嘱内容 住院)
     * @param '[map]'
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws
     * @author chengshaowei
     * @date 2016/9/19 10:33
     */
    public Map<String, Object> findHosAdvice(Map map) throws Exception {
        List list = this.queryForList("MpatientInfo.findHosAdvice", map);
        Map<String, Object> rmap = new HashMap<String, Object>();
        rmap.put("list", list);
        return rmap;
    }

    /**
     * @Description:(医技项目对应收费项目记录 门诊)
     * @param '[map]'
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws
     * @author chengshaowei
     * @date 2016/9/19 10:37
     */
    public Map<String, Object> findOutCharge(Map map) throws Exception {
        List list = this.queryForList("MpatientInfo.findOutCharge", map);
        Map<String, Object> rmap = new HashMap<String, Object>();
        rmap.put("list", list);
        return rmap;
    }

    /**
     * @Description:(医技项目对应收费项目记录 住院)
     * @param '[map]'
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws
     * @author chengshaowei
     * @date 2016/9/19 10:37
     */
    public Map<String, Object> findHosCharge(Map map) throws Exception {
        List list = this.queryForList("MpatientInfo.findHosCharge", map);
        Map<String, Object> rmap = new HashMap<String, Object>();
        rmap.put("list", list);
        return rmap;
    }

    /**
     * @Description:(医技项目执行明细记录)
     * @param '[map]'
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws
     * @author chengshaowei
     * @date 2016/9/19 10:37
     */
    public Map<String, Object> findDetail(Map map) throws Exception {
        List list = this.queryForList("MpatientInfo.findDetail", map);
        Map<String, Object> rmap = new HashMap<String, Object>();
        rmap.put("list", list);
        return rmap;
    }

    /**
     * @Description:(查询科室信息)
     * @param '[map]'
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws
     * @author chengshaowei
     * @date 2016/9/19 10:37
     */
    public Map<String, Object> findDepartment(Map map) throws Exception {
        List list = this.queryForList("MpatientInfo.findDepartment", map);
        Map<String, Object> rmap = new HashMap<String, Object>();
        rmap.put("list", list);
        return rmap;
    }

    /**
     * @Description:(查询参数信息)
     * @param '[map]'
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws
     * @author chengshaowei
     * @date 2016/9/19 10:37
     */
    public Map<String, Object> findParameters(Map map) throws Exception {
        return (Map<String, Object>) this.queryToObject("MpatientInfo.findParameters", map);
    }

    /**
     * @Description:(医技病人列表，通过费用查询)
     * @param '[map]'
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws
     * @author chengshaowei
     * @date 2016/9/19 10:30
     */
    public Map<String, Object> findMcostList(Map map) throws Exception {
        List list = this.queryForList("Mcost.findMcostList", map);
        Map<String, Object> rmap = new HashMap<String, Object>();
        rmap.put("list", list);
        return rmap;
    }


    /**
     * @Description:(医技病人列表，混合模式查询，医嘱+费用 0)
     * @param '[map]'
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws
     * @author chengshaowei
     * @date 2016/9/19 10:30
     */
    public Map<String, Object> findMhybridList(Map map) throws Exception {
        List list = this.queryForList("Mhybrid.findMhybridList", map);
        Map<String, Object> rmap = new HashMap<String, Object>();
        rmap.put("list", list);
        return rmap;
    }
    /**
     * @Description:(医技病人列表，混合模式查询，医嘱+费用 other)
     * @param '[map]'
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws
     * @author chengshaowei
     * @date 2016/9/19 10:30
     */
    public Map<String, Object> findOtherList(Map map) throws Exception {
        List list = this.queryForList("Mhybrid.findOtherList", map);
        Map<String, Object> rmap = new HashMap<String, Object>();
        rmap.put("list", list);
        return rmap;
    }

    /**
     * @Description:(修改抄嘱状态)
     * @param '[map]'
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws
     * @author chengshaowei
     * @date 2016/9/19 10:30
     */
    public void updateCostVaj1(List<Map<String,Object>> list) throws Exception {
        update("Mcost.updateCostVaj1",list);
    }

    /**
     * @Description:(修改抄嘱状态)
     * @param '[map]'
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws
     * @author chengshaowei
     * @date 2016/9/19 10:30
     */
    public void updateCostVaj2(List<Map<String,Object>> list) throws Exception {
        update("Mcost.updateCostVaj2",list);
    }

    /**
     * @Description:(员工检索 other)
     * @param '[map]'
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws
     * @author chengshaowei
     * @date 2016/9/19 10:30
     */
    public Map<String, Object> findStaff(Map map) throws Exception {
        List list = this.queryForList("Mhybrid.findStaff", map);
        Map<String, Object> rmap = new HashMap<String, Object>();
        rmap.put("list", list);
        return rmap;
    }

    /**
     * 院内消息查询
     *
     * @param map
     * @param currPage
     * @param pageSize
     * @return
     * @throws Exception
     */
    public Map<String, Object> yuanNeiNotice(Map<String, Object> map, int currPage, int pageSize) throws Exception {
        return queryForPage("MpatientInfo.yuanNeiNotice", map, currPage, pageSize);
    }

    public Map<String, Object> queryForPage(String sqlDef, Map<String, Object> param, int currPage, int pageSize) throws Exception {
        String getCountSqlDef = sqlDef + "Count";
        /*获取查询结果的记录总数*/
        int total = ((Integer) this.getSqlSession().selectOne(getCountSqlDef, param)).intValue();
        int pageIndex = currPage - 1;
        pageIndex = pageIndex < 0 ? 0 : pageIndex;
        int startNum1 = pageIndex * (pageSize < 1 ? 1 : pageSize);
        List list = this.getSqlSession().selectList(sqlDef, param, new RowBounds(startNum1, pageSize));
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("list", list);
        map.put("total", total);
        return map;
    }

    /**
     * chengshaowei 2017/7/27 9:38
     *
     * @param map
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws
     * @Title: findVAJ1
     * @Description: （查询门诊病人记账费用是否执行）
     */
    public Map<String, Object> findVAJ1(Map<String, Object> map) throws Exception {
        return (Map<String, Object>) getSqlSession().selectOne("medical_vaj.findVAJ1", map);
    }


    /**
     * chengshaowei 2017/7/27 9:38
     *
     * @param map
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws
     * @Title: findVAJ2
     * @Description: （查询住院病人记账费用是否执行）
     */
    public Map<String, Object> findVAJ2(Map<String, Object> map) throws Exception {
        return (Map<String, Object>) getSqlSession().selectOne("medical_vaj.findVAJ2", map);
    }

    /**
     * chengshaowei 2017/7/27 9:38
     *
     * @param map
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws
     * @Title: findInvalid
     * @Description: （查询住门诊用明细是否作废）
     */
    public List<Map<String, Object>> findInvalid(Map<String, Object> map) throws Exception {
        return queryForList("medical_vaj.findInvalid", map);
    }

    /**
     * chengshaowei 2017/8/15 14:10
     *
     * @param map
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws
     * @Title: findSumMoney
     * @Description: （计算医嘱费用）
     */
    public Map<String, Object> findSumMoney(Map<String, Object> map) throws Exception {
        return (Map<String, Object>) getSqlSession().selectOne("MpatientInfo.findSumMoney", map);
    }
    
    /**
     * 查询已经扣过费用的项目名称
     * @Title: findYetItem   
     * @Description: TODO(方法功能描述)
     * @param: @param map
     * @param: @return
     * @param: @throws Exception
     * @return: Map<String,Object>      
     * @throws
     */
    public List<Map<String, Object>> findYetItem(Map<String, Object> map) throws Exception {
    	return this.queryForList("MpatientInfo.findYetItem", map);
    }

}
